import React, { PureComponent } from 'react';
import { connect } from 'dva';
import { TreeSelect } from 'antd';

const TreeNode = TreeSelect.TreeNode;

@connect(({ category, loading }) => ({
    category,
    loading: loading.models.category,
}))
export class SelectCategory extends PureComponent {
    constructor(props) {
        super(props);
        this.state = {
            value: ''
        };
    }

    componentDidMount() {
        this.props.dispatch({
            type: 'category/fetchCategory'
        });
    }

    onChange = (value) => {
        // console.log(`on change${JSON.stringify(arguments)}`);
        this.setState({
            value: value
        })
    }

    render() {
        let { list } = this.props.category;
        return (
            <TreeSelect
                style={{ width: 300 }}
                value={this.state.value}
                dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
                treeData={list}
                placeholder="Please select"
                treeDefaultExpandAll
                onChange={this.onChange}
            />
        );
    }

}